# -*- coding: utf-8 -*-
import scrapy

class QsbkSpider(scrapy.Spider):
    name = 'qsbk'
    allowed_domains = ['qiushibaike.com']
    start_urls = ['https://www.qiushibaike.com/text/page/1']
    

    def parse(self, response):
        div_list = response.xpath('//div[@id="content-left"]/div[contains(@class, "article block")]')
        for div in div_list:
            item = {}
            item['user_name'] = div.xpath('.//a/h2/text()').extract_first()
            if item['user_name']:
                item['user_name'] = item['user_name'].strip()
            item['content'] = div.xpath('.//div[@class="content"]/span/text()').extract_first().strip()
            print(item)
        next_url = response.xpath('//span[@class="next"]/../@href').extract_first()
        print('下一页', next_url)
        if next_url:
            yield response.follow(
                next_url,
                callback=self.parse
            )